package com.itheima.test;

import java.util.ArrayList;

public class Test4 {
    public static void main(String[] args) {
        //需求：定义一个集合，添加一些学生对象，并进行遍历
        //学生类的属性为：姓名，年龄

        //1.定义一个集合
        ArrayList<Student> list = new ArrayList<>();

        //2.创建学生对象
        Student s1 = new Student("zhangsan", 23);
        Student s2 = new Student("lisi", 24);
        Student s3 = new Student("wangwu", 25);

        //3.添加学生对象
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //4.遍历集合
        for (int i = 0; i < list.size(); i++) {
            Student st = list.get(i);
            System.out.println("姓名：" + st.getName() + "   " + "年龄：" + st.getAge());
        }
    }
}
